# -*- coding:utf-8 -*-
import bottle,os,socket
from bottle import route, run, request,error

'''
k8s 测试使用
'''

#处理http请求

#bottle 默认会以get方法进行处理
@route('/ok/<name>')
def default(name):
  hostname=os.environ['HOSTNAME']
  hostip=socket.gethostbyname(hostname)
  query=request.query.name
  print("url")
  requesturl=request.url
  print("url_args")
  requesturl_args=request.url_args

  print("urlparts")
  print(request.urlparts)
  requestpth=request.path
  return '''<h1>Hello Wold! </h1> <br> Hostname: %s <hr> <br>
       IP: %s <hr> <br> requesturl:%s  <br>requestpth: %s <br>
       requesturl_args: %s 
       ''' % (hostname, hostip,requesturl,requestpth,requesturl_args)

@route('')
@route('/')
def loginpost():
  return '<h1>请使用  http://xxx/ok/x=x 形式进行测试</h1>'


@error(404)
def error404(error):
  return "<h1> 访问地址不存在，请返回首页重新测试 </h1>"



if __name__ == '__main__':
  bottle.run(host='0.0.0.0',port='8080')

  